#include <iostream>
#include <algorithm>
#include <cstring>

int const maxn = 50007;
int tree[maxn];
int id[maxn];
int len;
int a[maxn];
int b[maxn];
long long left[maxn][2];
long long right[maxn][2];
int n;

int lowbit(int x) { return x & -x; }

void init_tree()
{
	memset(tree, 0, sizeof(tree));
}

void update(int x, int d)
{
	for (; x <= len; x += lowbit(x)) tree[x] += d;
}

int query(int x)
{
	int ret = 0;
	for (; x > 0; x -= lowbit(x)) ret += tree[x];
	return ret;
}

int sum(int l, int r)
{
	if (l > r) return 0;
	return query(r) - query(l - 1);
}

int main()
{
	std::ios_base::sync_with_stdio(false);
	while (std::cin >> n) {
		for (int i = 1; i <= n; i++) {
			std::cin >> a[i];
			b[i - 1] = a[i];
		}
		std::sort(b, b + n);
		int tn = std::unique(b, b + n) - b;
		len = tn + 1;
		for (int i = 1; i <= n; i++)
			id[i] = std::lower_bound(b, b + tn, a[i]) - b + 1;

		init_tree();
		long long lt = 0, gt = 0;
		for (int i = 1; i <= n; i++) {
			int tid = id[i];
			left[i][0] = sum(1, tid - 1);
			left[i][1] = sum(tid + 1, len);
			update(tid, 1);
			lt += left[i][0];
			gt += left[i][1];
		}

		init_tree();
		for (int i = n; i >= 1; i--) {
			int tid = id[i];
			right[i][0] = sum(1, tid - 1);
			right[i][1] = sum(tid + 1, len);
			update(tid, 1);
		}

//		std::cout << lt << " " << gt << "\n";
		long long ans = lt * gt;
		for (int i = 1; i <= n; i++) {
			ans -= left[i][0] * right[i][0];
			ans -= left[i][1] * right[i][1];
			ans -= right[i][1] * right[i][0];
			ans -= left[i][1] * left[i][0];
		}

		std::cout << ans << "\n";
	}
}

